#ifndef _PT_TYPES_H_
#define _PT_TYPES_H_

typedef char  pt_char_t;
typedef char  pt_int8_t;
typedef short pt_int16_t;
typedef long  pt_int32_t;
typedef unsigned char  pt_uint8_t;
typedef unsigned short pt_uint16_t;
typedef unsigned long  pt_uint32_t;
typedef long pt_base_t;
typedef unsigned long pt_ubase_t;
typedef int pt_bool_t;

typedef pt_base_t   pt_err_t;		/* Type for error number.	*/
typedef pt_uint32_t pt_time_t;		/* Type for time stamp. 	*/
typedef pt_uint32_t pt_tick_t;		/* Type for tick count. 	*/
typedef pt_base_t  	pt_flag_t;		/* Type for flags.			*/
typedef pt_uint32_t	pt_size_t;		/* Type for size number.	*/
typedef pt_uint8_t	pt_dev_t;		/* Type for device			*/
typedef pt_int32_t	pt_off_t;		/* Type for offset, supports 4G at most */

/* bool type definitions */
#define PT_TRUE 			1
#define PT_FALSE 			0

#define PT_ALIGN_SIZE		4
#define PT_ALIGN(size, align)	(((size) + (align) - 1) & ~((align)-1))

/* RT-Thread error code definitions */
#define PT_EOK				0		/*!< There is no error happen. */
#define PT_ERROR			1		/*!< A generic error happens. 	*/
#define PT_ETIMEOUT			2		/*!< Some timing sensitive action failed, because timed out. */
#define PT_EFULL			3		/*!< The resource is full. */
#define PT_EEMPTY			4		/*!< The resource is empty. */
#define PT_ENOSYS			5		/*!< No system. */

#define PT_ASSERT(EX)		if (!(EX)) pt_assert(__FILE__, __LINE__);
#define PT_NULL 			((void *)0)

#ifdef _MSC_VER
#define pt_inline __inline
#else
#define pt_inline static inline
#endif

#define PT_MASK_DEF(value) (1 << (value))
#define PT_MASK_MATCH(value, mask) (((value) & (mask)) == (mask))
#define PT_ARRAY_SIZE(array)	(sizeof((array)) / sizeof((array)[0]))

#ifndef PT_UNUSED_ARG
#define PT_UNUSED_ARG(arg) (void)arg
#endif

#ifndef	 PT_OFFSETOF
#define PT_OFFSETOF(type, member) ((pt_size_t) &((type *)0)->member)
#define PT_CONTAINER_OF(ptr, type, member) ((type *)( (char *)(ptr) - PT_OFFSETOF(type,member)))
#endif

#endif
